# -*- encoding=utf8 -*-
__author__ = "chen"

from common.common_util import *


def yaocao(hwnd,n):
    connect_device(f"Windows:///{hwnd}")

    x = random.randint(-20, 20)
    y = random.randint(-5, 5)
    if n % 3 ==0:
        pos = exists(Template(r"water.png", record_pos=(0.339, -0.02), resolution=(1600, 900)))
        if pos:
            touch((pos[0] + x, pos[1]+y), times=1)
    elif n % 3 ==1:
        pos = exists(Template(r"shifei.png", record_pos=(0.345, 0.028), resolution=(1600, 900)))
        if pos:
            touch((pos[0] + x, pos[1] + y), times=1)
    else:
        pos = exists(Template(r"shachong.png", record_pos=(0.341, 0.081), resolution=(1600, 900)))
        if pos:
            touch((pos[0] + x, pos[1] + y), times=1)


def run_yaocao():
    hwnds = get_all_windows("梦幻西游")
    for i in range(1000):
        for hwnd in hwnds:
            yaocao(hwnd, i)
            sleep(2)

if __name__ == '__main__':
    run_yaocao()